
#ifndef __XML_DESCRIPTOR_H
#define __XML_DESCRIPTOR_H

#include <libxml/xpointer.h>
#include <apr_pools.h>
#include "../db/KeyDB.h"
#include "DOMDocument.h"

class XMLDescriptor
{
   public:
      XMLDescriptor();
      ~XMLDescriptor();
      int ReadEncrypted(KeyDB *keydb, const char *keyname, const char *filename, apr_pool_t *mp);
      int WriteEncrypted(KeyDB *keydb, const char *keyname, const char *filename, apr_pool_t *mp);
      int ReadPlain(const char *filename);
      int ReadPlain(const char *buffer, int length);
      int WritePlain(const char *filename);
      char *WritePlain();
      char *GetCapabilitiesString();
      apr_off_t GetNumberOfBlocks();
      apr_off_t GetUncompressedBlockSize();
      apr_off_t GetCompressedEncryptedSize(int block);
      const char *CalculateXORBlockHash(int numberofblocks);
      int AllocateFileSystemBlocks(AllDBs *dbs, const char *store_uuid, const char *username, int *mustreverse, int *errmsg, apr_pool_t *mp, apr_off_t *sizeused);
      int AllocateXMLDescribed(AllDBs *dbs, const char *store_uuid, const char *username, int *errmsg, const char *origination, apr_pool_t *mp, apr_off_t *sizeused);
      int GenerateXMLTreeForBlockTransfer(int *cancel, const char *cname, KeyPair *trialkey, const char *directorypath, apr_size_t blocksize, apr_pool_t *mp, int *blocks);
      int UnlinkXMLTreeForBlockTransfer();
      void GenerateInitialDescriptor(const char *workname, const char *examplechain, const char *caps, int secondsmax);
   private:
      DOMDocument *domd;
      xmlNodePtr GetBlockTransferNode();
      xmlNodePtr GetBlockNode(int block);
};

#endif
